<?php
class clsErrorMessages
{
	static public function addMessage($errorMessage, $type = 'error')
	{
		$errorString = "";
		if($type == "success")
		{
			$errorString .= "<tr class='messageStackSuccess'><td class='messageStackSuccess'>";
			$errorString .= "<img title='ICON_SUCCESS' alt='ICON_SUCCESS' src='".DIR_WS_IMAGES."icons/success.gif' border='0'>&nbsp;";
			$errorString .= $errorMessage;
			$errorString .= "</td></tr>";
		}
		elseif($type == "warning")
		{
			$errorString .= "<tr class='messageStackWarning'><td class='messageStackWarning'>";
			$errorString .= "<img title='ICON_WARNING' alt='ICON_WARNING' src='".DIR_WS_IMAGES."icons/warning.gif' border='0'>&nbsp;";
			$errorString .= $errorMessage;
			$errorString .= "</td></tr>";
		}
		else
		{
			$errorString .= "<tr class='messageStackError'><td class='messageStackError'>";
			$errorString .= "<img title='ICON_ERROR' alt='ICON_ERROR' src='".DIR_WS_IMAGES."icons/error.gif' border='0'>&nbsp;";
			$errorString .= $errorMessage;
			$errorString .= "</td></tr>";
		}
		if(isset($_SESSION[SESSION_ERRORS_NAME]))
		{
			$arrError = array();
			$arrError = $_SESSION[SESSION_ERRORS_NAME];
			$countError = count($arrError) + 1;
			$_SESSION[SESSION_ERRORS_NAME][$countError] = $errorString;
		}
		else
		{
			$_SESSION[SESSION_ERRORS_NAME][0] = $errorString;
		}
	}
	static public function showMessage()
	{
		$result = "";
		if(isset($_SESSION[SESSION_ERRORS_NAME]))
		{
			foreach ($_SESSION[SESSION_ERRORS_NAME] as $err)
			{
				$result .= $err;
			}
			unset($_SESSION[SESSION_ERRORS_NAME]);
			$result = "<table cellSpacing='0' cellPadding='2' width='100%' border='0' align='center'>" . clsErrorMessages::outputHtml($result) . "</table>";
		}
		return $result;
	}
	public static function outputHtml($string, $translate = false, $protected = false)
	{
		$str = "";
		if ($protected == true) {
		  $str = htmlspecialchars($string);
		} else {
		  if ($translate == false) {
			$str =  clsErrorMessages::parse_input_field_data($string, array('"' => '&quot;'));
		  } else {
			$str =  clsErrorMessages::parse_input_field_data($string, $translate);
		  }
		}
		$str = str_replace(chr(13),'',$str);
		$str = str_replace("\n",'',$str);
		return $str;
	}
	private static function parse_input_field_data($data, $parse) {
		return strtr(trim($data), $parse);
	}
}
?>